Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition associated to module reload and modulemanager #434

Conversation

jr0me
Copy link
Member

@jr0me jr0me commented Dec 16, 2024

Related issue
#432

Description

As described in the issue, the possibility of reloading modules requires some mechanism to avoid race conditions, in particular that the Agent stops the module manager when shutting down right before a ReloadModules command is received, resulting in two ModuleManager::Stop calls followed by a ModuleManager::Start halting the application.

The changes introduced by this PR are focused on improving thread safety and control mechanisms within the Wazuh Agent.

Tests

  • Compilation without warnings in every supported platform
    • Linux
    • Windows
    • MAC OS X

@jr0me jr0me linked an issue Dec 16, 2024 that may be closed by this pull request
@jr0me jr0me marked this pull request as ready for review December 16, 2024 19:30
Since commands may require ReloadModules to be called,
and they are run from coroutines, which can happen
on different threads, we need a way to limit when
such calls can happen.

ReloadModules will now be permitted only while the
Agent has finished starting up, and up until a signal
is received to shutdown.

For this a mutex and a flag have been added.

Also the TaskManager::Start call has been moved
to the Run() method. Because of this, m_agentThreadCount
had to be created.
Also, return from Start only when each
task queued into the task manager has been
called.
@jr0me jr0me force-pushed the fix/432-race-condition-associated-to-module-reload-and-modulemanager branch from 8361d8f to 87e13d4 Compare December 16, 2024 21:53
@vikman90 vikman90 merged commit 174f7cd into master Dec 17, 2024
5 checks passed
@vikman90 vikman90 deleted the fix/432-race-condition-associated-to-module-reload-and-modulemanager branch December 17, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition associated to module reload and ModuleManager
3 participants